<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>Document</title>
	</head>

	<body>
		<form action="https://www.baidu.com/s?">
			<input type="text" name="wd" />
			<input type="submit" value="搜索" />
		</form>
		<a href="http://www.baidu.com">百度一下</a>
		<script>
			const form = document.querySelector("form");
			form.addEventListener("submit", function (e) {
				// 阻止默认行为   提交 事件对象.preventDefault()
				e.preventDefault();
			});

			const a = document.querySelector("a");
			a.addEventListener("click", function (e) {
				// 阻止默认行为   提交 跳转

				if (!confirm("确定要跳转吗？")) {
					e.preventDefault();
				}
			});
		</script>
	</body>
</html>
